import request from '@/utils/request'
import {
  departmentInformation,
  ResponseData,
  departmentInformationResponseData,
  Alldepartment,
  departmentPage,
} from './type'
enum API {
  // 获取已有部门信息
  DEPARTMENTDATA_URL = 'department/getDepartmentPage/',
  DEPARTMENTPAGEDATA_URL = 'department/departmentPageData/',
  // 添加部门
  ADDDEPARTMENTDATA_URL = 'department/addDepartment/',
  // 修改部门
  UPDATEDEPARTMENTDATA_URL = 'department/updateDepartment/',
  // 删除部门
  DELETEDEPARTMENTDATA_URL = 'department/deleteDepartment/',
  // 获取所有部门信息list/
  GETALLDEPARETMENT_URL = 'department/getAllDepartment/',
}

// 获取已有会议室信息 两个参数(当前页,显示页数)
export const reqdepartmentData = (current: number, pageSize: number) =>
  request.get<any, departmentInformationResponseData>(
    API.DEPARTMENTDATA_URL + `${current}/${pageSize}`,
  )
//  获取已有会议室信息 (可以查询使用)
export const reqdepartmentpageData = (params: departmentPage) =>
  request.get<any, departmentInformationResponseData>(
    API.DEPARTMENTPAGEDATA_URL,
    { params: params },
  )

// 添加与修改会议室
export const reqAddOrUpdatedepartmentData = (data: departmentInformation) => {
  // 修改会议室数据
  if (data.id) {
    return request.put<any, ResponseData>(API.UPDATEDEPARTMENTDATA_URL, data)
  } else {
    return request.post<any, ResponseData>(API.ADDDEPARTMENTDATA_URL, data)
  }
}

export const reqDeletedepartmentData = (id: number) =>
  request.delete<any, ResponseData>(API.DELETEDEPARTMENTDATA_URL + `${id}`)

export const reqGetAlldepartment = () =>
  request.get<any, Alldepartment>(API.GETALLDEPARETMENT_URL)
